//
//  StatusCellBottomView.swift
//  Weibo10
//
//  Created by mac on 16/8/15.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class StatusCellBottomView: UIView {

    /**
    *  属性懒加载
    */
    
    // 转发按钮/weer鸟叫的意思
    private lazy var retweetedButton: UIButton = UIButton(title: "转发", fontSize: 12, color: UIColor.darkGrayColor(), imageName: "timeline_icon_retweet")
    
    // 评论按钮
    private lazy var commentButton: UIButton = UIButton(title: "评论", fontSize: 12, color: UIColor.darkGrayColor(), imageName: "timeline_icon_comment")
    
    // 点赞按钮
    private lazy var likeButton: UIButton = UIButton(title: "点赞", fontSize: 12, color: UIColor.darkGrayColor(), imageName: "timeline_icon_unlike")

    
    /**
    *  函数
    */
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    
}


// MARK: - 设置界面
extension StatusCellBottomView {
    
    // 创建分割视图/不要使用计算型属性 － 会让代码的阅读产生困难/使用函数来创建分割线
    private func sepView() -> UIView {
        // 初始化View
        let v = UIView()
        
        // 设施view的背景颜色
        v.backgroundColor = UIColor.darkGrayColor()
        
        return v
    }

    
    private func setupUI() {
        
        // 设置背景颜色
        backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        
        // 添加控件
        addSubview(retweetedButton)
        addSubview(commentButton)
        addSubview(likeButton)
        
        
        // 设置约束
        retweetedButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.bottom.equalTo(self.snp_bottom)
        }
        
        commentButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedButton.snp_top)
            make.left.equalTo(retweetedButton.snp_right)
            make.width.equalTo(retweetedButton.snp_width)
            make.height.equalTo(retweetedButton.snp_height)
        }
        
        likeButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(commentButton.snp_top)
            make.left.equalTo(commentButton.snp_right)
            make.width.equalTo(commentButton.snp_width)
            make.height.equalTo(commentButton.snp_height)
            
            make.right.equalTo(self.snp_right)
        }
        
        // 创建分割线
        let sep1 = sepView()
        let sep2 = sepView()
        
        addSubview(sep1)
        addSubview(sep2)
        
        // 如何设置分割线的约束
        let w = 0.5
        // 高度的比例
        let scale = 0.4
        
        sep1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedButton.snp_right)
            make.centerY.equalTo(retweetedButton.snp_centerY)
            make.width.equalTo(w)
            make.height.equalTo(retweetedButton.snp_height).multipliedBy(scale)
        }
        
        sep2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentButton.snp_right)
            make.centerY.equalTo(retweetedButton.snp_centerY)
            
            make.width.equalTo(w)
            make.height.equalTo(retweetedButton.snp_height).multipliedBy(scale)
        }
        
    }
 
}
